#include "manageraddnewperson.h"
#include "ui_manageraddnewperson.h"
#include <QDebug>
#include <QMessageBox>

managerAddNewPerson::managerAddNewPerson(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::managerAddNewPerson)
{
    ui->setupUi(this);
    this->setWindowTitle("添加学生/教师信息");
}

managerAddNewPerson::~managerAddNewPerson()
{
    delete ui;
}

void managerAddNewPerson::on_btn_comfirm_clicked()
{
    if(ui->edit_name->text()!=""&&ui->edit_id->text()!=""&&ui->edit_college->text()!=""&&ui->edit_password->text()!="")
    {
        if(this->ui->radbtn_student->isChecked()||this->ui->radbtn_teacher->isChecked())
        {
            setInfo();
            this->close();
        }
        else
        {
            QMessageBox::critical(this,"错误","请选择你要添加的角色！","确认");
        }
    }
    else
    {
        QMessageBox::critical(this,"错误","请输入完整信息！","确认");
    }
}

QStringList managerAddNewPerson::getInfo()
{
    return personInfo;
}

bool managerAddNewPerson::whoAreYou()
{
    if(this->ui->radbtn_student->isChecked())
    {
        return true;
    }
    else
    {
        return false;
    }
}

void managerAddNewPerson::setInfo()
{
    personInfo.clear();
    personInfo.append(this->ui->edit_name->text());
    personInfo.append(this->ui->edit_id->text());
    personInfo.append(this->ui->edit_college->text());
    personInfo.append(this->ui->edit_grade->text());
    personInfo.append(this->ui->edit_class->text());
    personInfo.append(this->ui->edit_major->text());
    personInfo.append(this->ui->edit_level->text());
    personInfo.append(this->ui->edit_password->text());
}

void managerAddNewPerson::clearUi()
{
    ui->edit_name->clear();
    ui->edit_id->clear();
    ui->edit_grade->clear();
    ui->edit_class->clear();
    ui->edit_college->clear();
    ui->edit_major->clear();
    ui->edit_password->clear();
    ui->edit_level->clear();
    personInfo.clear();
    personInfo.append("0");
}


void managerAddNewPerson::on_btn_exit_clicked()
{
    this->close();
}
